const Router = require('koa-router')
const collectArticles = new Router()
//！拿到前端的数据
//数据库连接池
const pg = require('pg');
let psql = new pg.Pool({
    database: 'running',
    user: 'run',
    port: 5432,
    host: '82.157.94.115',
    password: 'z12345678',
    max: 2
})

collectArticles.get('/collectArticles', async ctx => {
    let searchContentPostgresql = `select * from collectarticles`;
    let content = await psql.query(searchContentPostgresql);
    // console.log(content)
    // console.log("行数", content.rowCount)

    if (content.rowCount > 0) {
        var collectArticlesObj = [];
        for (var i = 0; i < content.rowCount; i++) {
            var obj = {
                content_id: content.rows[i].content_id,
                content_title: content.rows[i].content_title,
                content_content: content.rows[i].content_content,
                content_time: content.rows[i].content_time,
                content_img: content.rows[i].content_img
            }

            collectArticlesObj.push(obj);
        }

        ctx.body = {
            collectArticlesObj
        };
    }

})
module.exports = collectArticles